﻿using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

namespace YFrameWork.RunTime
{
    public static class UIComponentExtend 
    {

        /// <summary>
        /// 添加UIForm
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="UI"></param>
        /// <param name="canvasTran"></param>
        /// <param name="uIConfig"></param>
        public static void AddUIForm<T>(this UIComponent UI, Transform canvasTran, UIConfigItem uIConfig) where T : UICanvasBase
        {
            Type canvasBase = typeof(T);
            if (canvasBase == null)
            {
                Log.Error("要添加的Canavas是空的");
            }

            T canvasComponent = UI.GetOrAddUICanvas<T>();
            UI.AddUIFormToUICanvas(uIConfig.m_Type, canvasComponent);

            if (canvasTran != null)
            {
                canvasComponent.transform.SetParent(canvasTran);
            }

          
            
            UI.AddUIForm(uIConfig);
        }
    }
}